#include <iostream>
#include <iomanip>
#include "Common/Common.h"

using namespace std;

void PrintVec2(const Vec2& vec);
void PrintVec4(const Vec4& vec);
void PrintMatr4(const Matr4& matr);

int main()
{
	Matr4 identity;
    cout << "Identity:" << endl;
	PrintMatr4(identity);
    cout << endl;

	Transform tr0(Vec2(1.0f, -1.0f), 0.0f, 1.5f);
	Transform tr1(Vec2(2.0f, -1.0f), 0.25f * PI, 0.5f);
    Matr4 trMatr = tr1.GetMatrix();
    Matr4 trMatrInv0 = tr1.GetInvMatrix();
    Matr4 trMatrInv1 = trMatr.GetInverted();

    cout << "Transform Vec2(1.0f, -1.0f), 0.333f * PI:" << endl;
	PrintMatr4(trMatr);
    cout << endl;

    cout << "trMatrInv0:" << endl;
	PrintMatr4(trMatrInv0);
    cout << endl;

    cout << "trMatrInv1:" << endl;
	PrintMatr4(trMatrInv1);
    cout << endl;

    Vec2 right = Vec2::ZERO;
    Vec4 right4 = Vec4(right, 0.0f, 1.0f);

    Vec4 resultVec = Vec4( tr1 * right, 0.0f, 1.0f);
    Vec4 resultMatr = right4 * trMatr;
    Vec4 result0 = right4 * trMatrInv0;
    Vec4 result1 = right4 * trMatrInv1;


    cout << "resultVec:" << endl;
    PrintVec4(resultVec);
    cout << endl;

    cout << "resultMatr:" << endl;
    PrintVec4(resultMatr);
    cout << endl;

    cout << "result0:" << endl;
    PrintVec4(result0);
    cout << endl;

    cout << "result1:" << endl;
    PrintVec4(result1);
    cout << endl;

    return 0;
}

void PrintVec2(const Vec2& vec)
{
	int w = 6;
	cout << setiosflags(ios::fixed) << setprecision(2) <<
	setw(w) << vec.X << setw(w) << vec.Y << endl;
}

void PrintVec4(const Vec4& vec)
{
	int w = 6;
	cout << setiosflags(ios::fixed) << setprecision(2) <<
	setw(w) << vec.X << setw(w) << vec.Y << setw(w) << vec.Z << setw(w) << vec.W << endl;
}


void PrintMatr4(const Matr4& matr)
{
	int w = 6;
	cout << setiosflags(ios::fixed) << setprecision(2) <<
	setw(w) << matr[0] << setw(w) << matr[4] << setw(w) << matr[8] << setw(w) << matr[12] << endl <<
	setw(w) << matr[1] << setw(w) << matr[5] << setw(w) << matr[9] << setw(w) << matr[13] << endl <<
	setw(w) << matr[2] << setw(w) << matr[6] << setw(w) << matr[10] << setw(w) << matr[14] << endl <<
	setw(w) << matr[3] << setw(w) << matr[7] << setw(w) << matr[11] << setw(w) << matr[15] << endl;
}
